
#ifndef _BUTTON_HPP_
#define _BUTTON_HPP_

#include "CHIP_PIN.hpp"
typedef enum
{
    button_status_ok,
    button_status_fail,
} button_status;

typedef enum
{
    button_press_signal_non_pressed = 0,
    button_press_signal_pressed = 1,
    button_press_signal_long_pressed = 2,//大于2s小于4s
    button_press_signal_long_pressed_5s = 4,
} button_press_signal;

typedef enum
{
    button_press_signal_mode_HIGH_active,
    button_press_signal_mode_LOW_active,
} button_press_signal_mode;

class BUTTON_SIMPLE
{
private:
    CHIP_INPUT_PIN *button_pin;//传入输入简单模式的管脚
    button_press_signal_mode press_mode;
    rt_mutex_t press_lock;

    rt_event_t press_event;//按压事件

    rt_tick_t press_tick;//系统为1000HZ时一个tick为1ms

    button_status init_falg;

    void _count_press_time(rt_tick_t release_tick);
public:

    BUTTON_SIMPLE(CHIP_INPUT_PIN *button_pin,button_press_signal_mode press_mode);
    ~BUTTON_SIMPLE();

    void BUTTON_SIMPLE_update_in_thread();//新开一个独立线程并将其放入while(1)中运行

    button_press_signal BUTTON_SIMPLE_read_button_press_status();
    button_status BUTTON_SIMPLE_read_init_status();

};

#endif /* _BUTTON_HPP_ */
